package com.zsrt.java.day20161227.zzm.demo1;

import java.util.Arrays;
import java.util.Random;

public class DouDiZhu {


	public static void main(String[] args) {
		String[] a=getPai();
		a=getRandomPai(a);
		faPai(a);
	}
	public static String[] getPai(){
		String[] huaSe  = {"黑桃","红心","梅花","方块"};
		String[] paiNum = {"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
	    String[] pai = new String[54];
	    StringBuilder sb = new StringBuilder();	
		for(int color =0;color<huaSe.length;color++){
			for(int num = 0;num<paiNum.length;num++){
				String hua = huaSe[color];
				String p = hua.concat(paiNum[num]);
				sb.append(p+",");
			}
		}
		sb.append("大王,");
		sb.append("小王");
		System.out.println(sb.toString());
		String oldPai=sb.toString();
		pai=oldPai.split(",");
		
		
		return pai;
	}
	
	public static String[] getRandomPai(String[] pai){
		Random ran = new Random();
		int len  = (pai.length/3)-1;
		int len1 = pai.length/9;
		int len3 = pai.length/6;
		int temp = 0;
		String s="";
		for(int i=0;i<3;i++){
			for(int j=temp;j<len;j++){
				int index = ran.nextInt(len);
				s=pai[j];
				pai[j]=pai[index];
				pai[index]=s;
			}
			temp=len;
			len=len+17;
		}
	  
	   for(int a=0;a<6;a++){
		   for(int i=0;i<pai.length;i++){
	    	   int len2 = ran.nextInt(len1);
	    	   s=pai[i];
	    	   pai[i]=pai[len2];
	    	   pai[len2]=s;
	       }
		
	   }
	 
	   for(int a=0;a<9;a++){
		   for(int i=0;i<pai.length;i++){
	    	   int len4 = ran.nextInt(len3);
	    	   s=pai[i];
	    	   pai[i]=pai[len4];
	    	   pai[len4]=s;
	       }
	   }
     
	   
       for(int a=0;a<9;a++){
		   for(int i=0;i<pai.length;i++){
	    	   int len4 = ran.nextInt(len3);
	    	   s=pai[i];
	    	   pai[i]=pai[len4];
	    	   pai[len4]=s;
	       }
	   }
       return pai;
	}
	
	public static String[] faPai(String[] pai){
		
		int len = (pai.length/3)-1;
		String[] wj1 = new String[17];
		String[] wj2 = new String[17];
		String[] wj3 = new String[17];
		String[] dz  = new String[3];
		

		int temp = 0;
		
		for(int i=0;i<3;i++){
			for(int j=temp;j<len;j++){
				if(i==0){
					wj1[j]=pai[j];
				  
					
				}else if(i==1){
					wj2[j-17]=pai[j];
				
				}else if(i==2){
					if(j<=50){
					wj3[j-34]=pai[j];
					
					if(j==50){
						dz[0]=pai[j+1];
						dz[1]=pai[j+2];
						dz[2]=pai[j+3];
					}
					}
						
				}
			}
			temp=len;
			len=len+17;
		}
	
		System.out.println("玩家1:"+Arrays.toString(wj1));
		System.out.println("玩家2:"+Arrays.toString(wj2));
		System.out.println("玩家3:"+Arrays.toString(wj3));
		System.out.println("地主牌:"+Arrays.toString(dz));
		return pai;
	}
}
